<?php
	
	class upload {
	
		function upload_foto($gambar = null, $foto = null, $dir){
			$set = false;
			$keterangan = null;
			
			if ($foto != null) {
				if($foto["name"] != ""){
					$allowedExts = array("jpg", "jpeg", "png");
					$extension = end(explode(".", $_FILES[$gambar]["name"]));
					if ((($foto["type"] == "image/jpeg") || ($foto["type"] == "image/png") || ($foto["type"] == "image/pjpeg")) && ($foto["size"] < 200000)	&& in_array($extension, $allowedExts)) 
					{
						if($foto["error"] > 0) {
							$keterangan = 'gambar error';
							$set = false;
						}
						else {
							if (file_exists($dir."/" . $foto["name"]))
							  {
								$keterangan = 'gambar sudah ada';
								$set = false;
							  }
							else
							  {
								  move_uploaded_file($foto["tmp_name"], $dir."/" . $foto["name"]);
								  $keterangan = $dir."/" . $foto["name"];
								  $set = true;
							  }
						}
					}
					
					else {
						$keterangan = 'gambar tidak memenuhi persyaratan';
						$set = false;
					}
				}
			}
			
			$result = array(
				'set' => $set,
				'keterangan' => $keterangan
			);
					
			return $result;
		}
		
	}
	
?>